package com.tjmc.company.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.CompanyImgInfoEntity;
import com.tjmc.company.service.CompanyImgInfoService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 企业相册信息表
 *
 * @author recruit
 * @date 2024-11-14 16:56:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/companyImgInfo" )
@Tag(description = "companyImgInfo" , name = "企业相册信息表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CompanyImgInfoController {

    private final CompanyImgInfoService companyImgInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param companyImgInfo 企业相册信息表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getCompanyImgInfoPage(@ParameterObject Page page, @ParameterObject CompanyImgInfoEntity companyImgInfo) {
        LambdaQueryWrapper<CompanyImgInfoEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(companyImgInfoService.page(page, wrapper));
    }


    /**
     * 通过条件查询企业相册信息表
     * @param companyImgInfo 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject CompanyImgInfoEntity companyImgInfo) {
        return R.ok(companyImgInfoService.list(Wrappers.query(companyImgInfo)));
    }

    /**
     * 新增或修改企业相册信息表
     * @param companyImgInfoList 企业相册信息表
     * @return R
     */
    @Operation(summary = "新增或修改企业相册信息表" , description = "新增或修改企业相册信息表" )
    @SysLog("新增或修改企业相册信息表" )
    @PostMapping
    public R save(@RequestBody List<CompanyImgInfoEntity> companyImgInfoList) {
        List<Long> list = companyImgInfoList.stream().map(CompanyImgInfoEntity::getCompanyId).toList();
        companyImgInfoService.remove(new LambdaQueryWrapper<>(CompanyImgInfoEntity.class).in(CompanyImgInfoEntity::getCompanyId, list));
        return R.ok(companyImgInfoService.saveBatch(companyImgInfoList));
    }

}
